/* **************************************************************************/
/*COPYRIGHT CCWIN-IN ALL RIGHTS RESERVED. THIS IS AN UNPUBLISHED WORK.      */
/*V8:ConvertMode=Report                                                     */
/*V8:WebEnabled=Yes                                                         */
/*V8:RunMode=Character,Windows                                              */
/*EXTRACTING DATA FROM MFG/PRO                                              */
/****************************************************************************/
/* PROCEDURE NAME        : xxcstalljournalentry_e .p                        */
/* PROCEDURE TYPE        : Variance allocation journal entry program        */
/* DESCRIPTION           : Variance allocation journal entry program        */
/*                                                                          */     
/* INCLUDE FILES         :                                                  */
/* CALLED BY             :                                                  */
/* CALLED PROCEDURES     :                                                  */
/****************************************************************************/
/* CREATED BY            : Gaoyan                               24-Aug-19   */
/****************************************************************************/ 
/****************************************************************************/
/****************************************************************************/
											 
using com.qad.eefin.buser.EntitySecurityCheck.

&scoped-define TimeStamp STRING(MONTH(TODAY),"99") + STRING(DAY(TODAY),"99") +~
                         STRING(YEAR(TODAY),"9999") +~
                         SUBSTRING(STRING(TIME,"HH:MM:SS"),1,2) +~
                         SUBSTRING(STRING(TIME,"HH:MM:SS"),4,2) +~
                         SUBSTRING(STRING(TIME,"HH:MM:SS"),7,2)
                         
{us/mf/mfdtitle.i}
{us/gp/gpglefdf.i }						

/* Variable definitions */
DEFINE VARIABLE entity              LIKE  en_entity   FORMAT "x(8)"     NO-UNDO.
DEFINE VARIABLE site                LIKE  si_site                       NO-UNDO.
DEFINE VARIABLE li_year             LIKE  glc_year                      NO-UNDO.
DEFINE VARIABLE li_period           LIKE  glc_per                       NO-UNDO.
DEFINE VARIABLE lastyear             LIKE  glc_year                      NO-UNDO.
DEFINE VARIABLE lastperiod           LIKE  glc_per                       NO-UNDO.
DEFINE VARIABLE li_cur_yr           LIKE  glc_year                      NO-UNDO.
DEFINE VARIABLE li_cur_per          LIKE  glc_per                       NO-UNDO.
DEFINE VARIABLE ld_start_dt         LIKE  glc_start                     NO-UNDO.
DEFINE VARIABLE ld_end_dt           LIKE  glc_end                       NO-UNDO.
DEFINE VARIABLE li_access           AS    INTEGER                       NO-UNDO.
DEFINE VARIABLE lc_tmpstr           AS    CHARACTER                     NO-UNDO.
DEFINE VARIABLE li_success          AS    LOGICAL                       NO-UNDO.
DEFINE VARIABLE lc_tmpyn            AS    LOGICAL                       NO-UNDO.
DEFINE VARIABLE lc_log_file         AS    CHARACTER   FORMAT "x(40)"    NO-UNDO. 
DEFINE VARIABLE lc_to_code          AS    CHARACTER   INIT "UTF-8"      NO-UNDO. 
DEFINE VARIABLE li_update           as   logic                          no-undo.

/* For calling QAD Financials Data Object to check GL Entity Security */
DEFINE VARIABLE hQADFinancialsLib   AS    HANDLE                        NO-UNDO.
DEFINE VARIABLE EntitySecurity      AS    EntitySecurityCheck           NO-UNDO.
DEFINE VARIABLE valid_entity        LIKE  mfc_logical                   NO-UNDO.
DEFINE VARIABLE BufErrorMessage     AS    CHARACTER                     NO-UNDO.
DEFINE VARIABLE ErrorMessage        AS    CHARACTER                     NO-UNDO.

define variable codevaluein         as    character                     no-undo.
define variable codevalueout        as    character                     no-undo.
define variable jedesc              as    character                     no-undo.


define temp-table tt_xxcstallhist like xxcstall_hist                    .
define temp-table tt_xxcstalljehist like xxcstallje_hist                .		
define buffer b_codemstr for code_mstr.			

define variable lvi_row_id                   as decimal     no-undo.

function fiGetNextRowID returns decimal:
        lvi_row_id = lvi_row_id + 1000.
        return lvi_row_id.
        end function. /* fiGetNextRowID */ 	  

	
FORM
    entity     COLON 20 
    site       COLON 20 
    li_year    COLON 20 
    li_period  COLON 20 
	li_update  colon 20
    WITH FRAME a WIDTH 80 SIDE-LABELS .
    setFrameLabels(FRAME a:HANDLE).

/* Main Loop starts */
mainloop:
REPEAT TRANSACTION ON ERROR UNDO mainloop, RETRY mainloop:
   
   ASSIGN entity           = ""
          site             = ""
          li_year          = YEAR(TODAY)
          li_period        = MONTH(TODAY)
          lc_log_file      = "history_load_" +
                             {&TimeStamp} + ".txt"
          .
   
   
   FIND FIRST glc_cal NO-LOCK WHERE glc_domain = global_domain
                                AND glc_start <= TODAY
                                AND glc_end   >= TODAY NO-ERROR.
   IF AVAILABLE glc_cal THEN 
      ASSIGN li_cur_yr  = glc_year 
             li_cur_per = glc_per
             li_year    = glc_year
             li_period  = glc_per.
   
   CLEAR FRAME a NO-PAUSE.
   
   UPDATE entity   
          WITH FRAME a EDITING:
          
      {us/mf/mfnp05.i en_mstr en_entity "en_domain = global_domain" 
                      en_entity "input entity "}
      IF recno <> ? THEN DO:
         ASSIGN entity = en_entity.
         DISPLAY
            entity
         WITH FRAME a.
      END.         
   END. /* UPDATE EDITING entity */
   
   
   IF NOT CAN-FIND( FIRST en_mstr WHERE en_domain = global_domain 
                                   AND en_entity = entity)
   THEN DO:
      /* Invalid entity */
      {us/bbi/pxmsg.i &MSGNUM=3061 &ERRORLEVEL=3}
      NEXT-PROMPT entity WITH FRAME a.
      UNDO, RETRY.
   END. /* IF NOT CAN-FIND(FIRST */
      
   /* CHECK ENTITY SECURITY */
   IF entity <> "" THEN DO:    
      {us/gl/glenchk.i &entity=entity &entity_ok=valid_entity} 
      IF NOT valid_entity THEN DO:
         NEXT-PROMPT entity WITH FRAME a.
         UNDO, RETRY.
      END.     
   END. /* IF entity <> "" */
   
   siloop:
   DO ON ERROR UNDO siloop, RETRY siloop:
      
      UPDATE site     
           WITH FRAME a EDITING:
         
         {us/mf/mfnp05.i si_mstr si_site "si_domain = global_domain" 
                            si_site "input site"}
            IF recno <> ? THEN DO:
               ASSIGN site = si_site.
               DISPLAY site WITH FRAME a.
            END.            
      END. /* UPDATE EDITING site */
      
      IF NOT CAN-FIND( FIRST si_mstr WHERE si_domain = global_domain 
                                      AND si_site   = site
									  AND si_entity = entity) 
      THEN DO:
         /* Invalid Site */
         {us/bbi/pxmsg.i &msgnum=2797 &errorlevel=3 }
         NEXT-PROMPT site WITH FRAME a.
         UNDO siloop, RETRY siloop.
      END.

      /* Site Security Check */
      {us/bbi/gprun.i ""gpsiver.p"" "(INPUT site,?,OUTPUT li_access)"}
      IF li_access = 0 THEN DO:
         /* User does not have access to this site */
         {us/bbi/pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         NEXT-PROMPT site.
         UNDO siloop, RETRY siloop.
      END. /* IF li_access = 0 */      
   END. /* siloop */
   
   yrloop:
   DO ON ERROR UNDO yrloop, RETRY yrloop:
   
         UPDATE li_year  
             li_period WITH FRAME a.
       /*      
      IF LENGTH(li_year) <> 4 THEN DO:
         {us/bbi/pxmsg.i &msgnum=3900 &errorlevel=1 &msgarg1=""Year"" }
         NEXT-PROMPT li_year.
         UNDO yrloop, RETRY yrloop.
      END.
            
      IF li_period < 1 OR li_period > 12 THEN DO:
         {us/bbi/pxmsg.i &msgnum=282 &errorlevel=1 &msgarg1=""Period"" }
         NEXT-PROMPT li_period.
         UNDO yrloop, RETRY yrloop.
      END.
      */
   END. /* yrloop */
   
   Update li_update WITH FRAME a.
   
   empty temp-table tt_xxcstallhist.
   
	if li_period + 1 = 13 then 
    assign
    lastyear   = li_year + 1	
	lastperiod = 1.
	else 
	assign
	lastperiod = li_period + 1
	lastyear   = li_year.
	
    for first xxcstctrl_ctrl where xxcstctrl_ctrl.xxcstctrl_domain = global_domain 
                           and xxcstctrl_ctrl.xxcstctrl_entity = entity 
			               and xxcstctrl_ctrl.xxcstctrl_site = site 
                           and xxcstctrl_ctrl.xxcstctrl_ID  = ""  
						   and xxcstctrl_ctrl.xxcstctrl_year = lastyear
						   and xxcstctrl_ctrl.xxcstctrl_per = lastperiod:
    end. /*for first xxcstctrl_ctrl.xxcstctrl_file*/
    if not available xxcstctrl_ctrl then do:
	{us/bbi/pxmsg.i &MSGNUM=3966  &ERRORLEVEL=4 &PAUSEAFTER }
	Leave.
	end.
	
	if available xxcstctrl_ctrl then do:
	empty temp-table tt_xxcstallhist.
	empty temp-table tt_xxcstalljehist.
     /**   Step 1 Labor Burden Ovherhead carried forword **/ 
	 /**   Step 2 Purchase variance to Manufacturing part    **/  
	 /**   Step 3 Purchase variance Issue ***/
		  
     /**   Step 4 Manufacturing variance to parent part ***/
     /**   Step 5 Purchase variance Issue ***/
     /**   Step 6 Output Result **/	 
	 for each xxcstall_hist where xxcstall_hist.xxcstall_domain = global_domain
	                          and xxcstall_hist.xxcstall_entity = entity
							  and xxcstall_hist.xxcstall_site   = site
	                          and xxcstall_hist.xxcstall_year   = li_year
							  and xxcstall_hist.xxcstall_period = li_period
							  no-lock.
	
			find pt_mstr where pt_domain = global_domain
			               and pt_part   = xxcstall_hist.xxcstall_part
						   no-lock no-error.
 			find pl_mstr where pl_domain = global_domain
			               and pl_prod_line = pt_prod_line
						   no-lock no-error.

		    codevaluein = "".
            codevalueout = "".	
            jedesc       = "".			
			status default xxcstall_hist.xxcstall_part .
			if xxcstall_hist.xxcstall_scurbdnrate <> 0 then do:
			assign
			codevaluein = "transition-in-burden"
			codevalueout = "transition-out-burden".
			find code_mstr where code_mstr.code_domain  = global_domain
			                 and code_mstr.code_fldname = "xxcstallocation"
			                 and code_mstr.code_value   = codevaluein
							 no-lock no-error.
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   =  codevalueout
							 no-lock no-error.	
			jedesc   = GetTermLabel("TRANSITION-IN-BURDEN",30).
            run CreateJE (input code_mstr.code_cmmt,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input "DEF",
						 input pl_mstr.pl_inv_cc,
						 input "DEF",
						 input pt_mstr.pt_part_type,
						 input "DEF",
						 input pt_mstr.pt_group,
						 input "DEF",
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurbdnrate).				 

       end. /* if xxcstall_hist.xxcstall_scurbdnrate xxcstall_hist.xxcstall_scurlbrrate <> 0 */
			if xxcstall_hist.xxcstall_scurlbrrate <> 0 then do:
			assign
			codevaluein = "transition-in-labor"
			codevalueout = "transition-out-labor".
			find code_mstr where code_mstr.code_domain  = global_domain
			                 and code_mstr.code_fldname = "xxcstallocation"
			                 and code_mstr.code_value   = codevaluein
							 no-lock no-error.
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   =  codevalueout
							 no-lock no-error.	
		    jedesc   = GetTermLabel("TRANSITION-IN-LABOR",30).
            run CreateJE(input code_mstr.code_cmmt,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input "DEF",
						 input pl_mstr.pl_inv_cc,
						 input "DEF",
						 input pt_mstr.pt_part_type,
						 input "DEF",
						 input pt_mstr.pt_group,
						 input "DEF",
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurlbrrate).				 

       end. /* if  xxcstall_hist.xxcstall_scurlbrrate <> 0 */			  
	   /*** for YFPO 
	   if xxcstall_hist.xxcstall_scurothers <> 0 then do:
			assign
			codevaluein = "transition-in-overhead"
			codevalueout = "transition-out-overhead".
			find code_mstr where code_mstr.code_domain  = global_domain
			                 and code_mstr.code_fldname = "xxcstallocation"
			                 and code_mstr.code_value   = codevaluein
							 no-lock no-error.
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   =  codevalueout
							 no-lock no-error.	
		    jedesc   = GetTermLabel("TRANSITION-IN-OVERHEAD",30).
            run CreateJE(input code_mstr.code_cmmt,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input "DEF",
						 input pl_mstr.pl_inv_cc,
						 input "DEF",
						 input pt_mstr.pt_part_type,
						 input "DEF",
						 input pt_mstr.pt_group,
						 input "DEF",
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurothers).				 

       end. /* if  xxcstall_hist.xxcstall_scurothers <> 0 */			
	   for YFPO ***/
      /*** Purchase Variable to Manufacturing Parts Journal Entry create   ***/
	  assign
			codevaluein = "transition-in-raw".
			find code_mstr where code_mstr.code_domain  = global_domain
			                 and code_mstr.code_fldname = "xxcstallocation"
			                 and code_mstr.code_value   = codevaluein
							 no-lock no-error.
		    jedesc   = GetTermLabel("TRANSITION-OUT-RAW",30).
 	  if xxcstall_hist.xxcstall_curisswoppv <> 0 then do:

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_ppv_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisswoppv).	     			
      end. 
	  if xxcstall_hist.xxcstall_curisswoapusage <> 0 then do:
            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_apvu_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisswoapusage).	     			
      end. 
 	  if xxcstall_hist.xxcstall_curisswoaprate <> 0 then do:
            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_apvr_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisswoaprate).	     			
      end. 
 	  if xxcstall_hist.xxcstall_curisswocstadj <> 0 then do:
            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_cchg_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisswocstadj).	     			
      end. 	 
	  /** carry in raw variance to MF part */
	  jedesc   = GetTermLabel("TRANSITION-IN-RAW",30).
 	  if xxcstall_hist.xxcstall_scurraw <> 0 then do:
            run CreateJE(input code_mstr.code_cmmt,
			             input code_mstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input "DEF",
						 input pl_mstr.pl_inv_cc,
						 input "DEF",
						 input pt_mstr.pt_part_type,
						 input "DEF",
						 input pt_mstr.pt_group,
						 input "DEF",
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurraw).     			
      end. 	 	

      /*** MF Variable to Parent Manufacturing Parts Journal Entry create   ***/
	  /*** carry out MF variance                                            ***/
	  assign
			codevaluein = "transition-in-sfg".
			find code_mstr where code_mstr.code_domain  = global_domain
			                 and code_mstr.code_fldname = "xxcstallocation"
			                 and code_mstr.code_value   = codevaluein
							 no-lock no-error.
		    jedesc   = GetTermLabel("TRANSITION-OUT-SFG",30).
 	  if xxcstall_hist.xxcstall_scurisswomusage <> 0 then do:

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_mvar_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswomusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurisswomrate <> 0 then do:

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_mvrr_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswomrate).	
        end.
 	  if xxcstall_hist.xxcstall_scurisswosubrate <> 0 then do:

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_svar_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswosubrate).	
        end.	
 	  if xxcstall_hist.xxcstall_scurisswosubusage <> 0 then do:

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_svrr_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswosubusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurisswommthd <> 0 then do:

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_wvar_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswommthd).	
        end.
 	  if xxcstall_hist.xxcstall_scurisswocstadj <> 0 then do:

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_cchg_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswocstadj).	
        end.
		if xxcstall_hist.xxcstall_scurisswolbrusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input code_mstr.code_cmmt,
			             input dpt_mstr.dpt_lvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswolbrusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurisswobdnusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input code_mstr.code_cmmt,
			             input dpt_mstr.dpt_bvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswobdnusage).	
        end.		
 	  if xxcstall_hist.xxcstall_scurisswobdnrate <> 0 then do:
     assign
			codevaluein = "transition-in-burden".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input code_mstr.code_cmmt,
			             input b_codemstr.code_cmmt,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswobdnrate).	
        end.
	  if xxcstall_hist.xxcstall_scurisswolbrrate <> 0 then do:
       assign
			codevaluein = "transition-in-labor".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input code_mstr.code_cmmt,
			             input b_codemstr.code_cmmt,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswolbrrate).	
        end.	
	  if xxcstall_hist.xxcstall_scurissworaw <> 0 then do:
       assign
			codevaluein = "transition-in-raw".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input code_mstr.code_cmmt,
			             input b_codemstr.code_cmmt,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissworaw).	
        end.
	  if xxcstall_hist.xxcstall_scurisswosf <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input code_mstr.code_cmmt,
			             input b_codemstr.code_cmmt,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswosf).	
        end.
	  if xxcstall_hist.xxcstall_scurisswoothers <> 0 then do:
       

            run CreateJE(input code_mstr.code_cmmt,
			             input pl_mstr.pl_ovh_acct,
						 input "DEF",
						 input pl_mstr.pl_inv_sub,
						 input "DEF",						 
						 input pl_mstr.pl_inv_cc,
						 input "DEF",						 
						 input pt_mstr.pt_part_type,
						 input "DEF",						 
						 input pt_mstr.pt_group,  
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisswoothers).	
        end.		
     /*** SFG carry in end   ***/
      /** carry in SF variance to PARENT MF part */
	  jedesc   = GetTermLabel("TRANSITION-IN-SFG",30).
 	  if xxcstall_hist.xxcstall_scursf <> 0 then do:
            run CreateJE(input code_mstr.code_cmmt,
			             input code_mstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input "DEF",
						 input pl_mstr.pl_inv_cc,
						 input "DEF",
						 input pt_mstr.pt_part_type,
						 input "DEF",
						 input pt_mstr.pt_group,
						 input "DEF",
						 input jedesc,
						 input xxcstall_hist.xxcstall_scursf).     			
      end. 	 	
	  
	  /** ISS-UNP Journal Entry Create **/
	  
	  jedesc  = GetTermLabel("ISSUNP-RAW",30).
	  if xxcstall_hist.xxcstall_curissunpppv <> 0 then do:
	        run CreateJE(input pl_mstr.pl_fsdef_acct,
						 input pl_mstr.pl_ppv_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curissunpppv).	    
	  end.
	  if xxcstall_hist.xxcstall_curissunpapusage <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_apvu_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curissunpapusage).	     			
      end. 
 	  if xxcstall_hist.xxcstall_curissunpaprate <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_apvr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curissunpaprate).	     			
      end. 
 	  if xxcstall_hist.xxcstall_curissunpcstadj <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curissunpcstadj).	     			
      end. 	 
	  jedesc   = GetTermLabel("ISSUNP-SFG",30).
 	  if xxcstall_hist.xxcstall_scurissunpmusage <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_mvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpmusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurissunpmrate <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_mvrr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpmrate).	
        end.
 	  if xxcstall_hist.xxcstall_scurissunpsubrate <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_svar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpsubrate).	
        end.	
 	  if xxcstall_hist.xxcstall_scurissunpsubusage <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_svrr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpsubusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurissunpmmthd <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_wvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpmmthd).	
        end.
 	  if xxcstall_hist.xxcstall_scurissunpcstadj <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpcstadj).	
        end.
	  if xxcstall_hist.xxcstall_scurissunplbrusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input dpt_mstr.dpt_lvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunplbrusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurissunpbdnusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input dpt_mstr.dpt_bvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpbdnusage).	
        end.		
 	  if xxcstall_hist.xxcstall_scurissunpbdnrate <> 0 then do:
     assign
			codevaluein = "transition-in-burden".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpbdnrate).	
        end.
	  if xxcstall_hist.xxcstall_scurissunplbrrate <> 0 then do:
       assign
			codevaluein = "transition-in-labor".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunplbrrate).	
        end.	
	  if xxcstall_hist.xxcstall_scurissunpraw <> 0 then do:
       assign
			codevaluein = "transition-in-raw".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpraw).	
        end.
	  if xxcstall_hist.xxcstall_scurissunpsf <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpsf).	
        end.
	  if xxcstall_hist.xxcstall_scurissunpothers <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsdef_acct,
			             input pl_mstr.pl_ovh_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,  
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurissunpothers).	
        end.		  
	  
	  
  
	  /** CYCCNT Journal Entry Create **/
	  
	  	  jedesc  = GetTermLabel("CYCCNT-RAW",30).
	  if xxcstall_hist.xxcstall_curcyccntppv <> 0 then do:
	        run CreateJE(input pl_mstr.pl_fsaccr_acct,
						 input pl_mstr.pl_ppv_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curcyccntppv).	    
	  end.
	  if xxcstall_hist.xxcstall_curcyccntapusage <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_apvu_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curcyccntapusage).	     			
      end. 
 	  if xxcstall_hist.xxcstall_curcyccntaprate <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_apvr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curcyccntaprate).	     			
      end. 
	  
 	  if xxcstall_hist.xxcstall_curcyccntcstadj <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curcyccntcstadj).	     			
      end. 	
       
	  jedesc   = GetTermLabel("CYCCNT-SFG",30).
 	  if xxcstall_hist.xxcstall_scurcyccntmusage <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_mvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntmusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurcyccntmrate <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_mvrr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntmrate).	
        end.
 	  if xxcstall_hist.xxcstall_scurcyccntsubrate <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_svar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntsubrate).	
        end.	
 	  if xxcstall_hist.xxcstall_scurcyccntsubusage <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_svrr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntsubusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurcyccntmmthd <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_wvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntmmthd).	
        end.
 	  if xxcstall_hist.xxcstall_scurcyccntcstadj <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntcstadj).	
        end.
	  if xxcstall_hist.xxcstall_scurcyccntlbrusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input dpt_mstr.dpt_lvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntlbrusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurcyccntbdnusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input dpt_mstr.dpt_bvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntbdnusage).	
        end.		
 	  if xxcstall_hist.xxcstall_scurcyccntbdnrate <> 0 then do:
     assign
			codevaluein = "transition-in-burden".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntbdnrate).	
        end.
	  if xxcstall_hist.xxcstall_scurcyccntlbrrate <> 0 then do:
       assign
			codevaluein = "transition-in-labor".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntlbrrate).	
        end.	
	  if xxcstall_hist.xxcstall_scurcyccntraw <> 0 then do:
       assign
			codevaluein = "transition-in-raw".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntraw).	
        end.
	  if xxcstall_hist.xxcstall_scurcyccntsf <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntsf).	
        end.
	  if xxcstall_hist.xxcstall_scurcyccntothers <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsaccr_acct,
			             input pl_mstr.pl_ovh_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,  
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurcyccntothers).	
        end.
	  /** ISS-SO Journal Entry Create **/	 
	  jedesc  = GetTermLabel("ISSSO-RAW",30).
	  if xxcstall_hist.xxcstall_curisssoppv <> 0 then do:
	        run CreateJE(input pl_mstr.pl_fslbr_acct,
						 input pl_mstr.pl_ppv_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisssoppv).	    
	  end.
	  if xxcstall_hist.xxcstall_curisssoapusage <> 0 then do:
            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input pl_mstr.pl_apvu_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisssoapusage).	     			
      end. 
 	  if xxcstall_hist.xxcstall_curisssoaprate <> 0 then do:
            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input pl_mstr.pl_apvr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisssoaprate).	     			
      end. 
 	  if xxcstall_hist.xxcstall_curisssocstadj <> 0 then do:
            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_curisssocstadj).	     			
      end. 	 
	  jedesc   = GetTermLabel("ISSSO-SFG",30).
 	  if xxcstall_hist.xxcstall_scurisssomusage <> 0 then do:

            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input pl_mstr.pl_mvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssomusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssomrate <> 0 then do:

            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input pl_mstr.pl_mvrr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssomrate).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssosubrate <> 0 then do:

            run CreateJE(input pl_mstr.pl_rmar_acct,
			             input pl_mstr.pl_svar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssosubrate).	
        end.	
 	  if xxcstall_hist.xxcstall_scurisssosubusage <> 0 then do:

            run CreateJE(input pl_mstr.pl_rmar_acct,
			             input pl_mstr.pl_svrr_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssosubusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssommthd_mtl <> 0 then do:

            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input pl_mstr.pl_wvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssommthd_mtl).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssommthd_lbr <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsbdn_acct,
			             input pl_mstr.pl_wvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssommthd_lbr).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssommthd_bdn <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsexp_acct,
			             input pl_mstr.pl_wvar_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssommthd_bdn).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssocstadj_mtl <> 0 then do:

            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssocstadj_mtl).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssocstadj_lbr <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsbdn_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssocstadj_lbr).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssocstadj_bdn <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsexp_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssocstadj_bdn).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssocstadj_ovh <> 0 then do:

            run CreateJE(input pl_mstr.pl_fsexd_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssocstadj_ovh).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssocstadj_sub <> 0 then do:

            run CreateJE(input pl_mstr.pl_rmar_acct,
			             input pl_mstr.pl_cchg_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,						 
						 input pl_mstr.pl_inv_cc,
						 input pl_mstr.pl_inv_cc,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_part_type,					 
						 input pt_mstr.pt_group,
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssocstadj_sub).	
        end.
	  if xxcstall_hist.xxcstall_scurisssolbrusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsbdn_acct,
			             input dpt_mstr.dpt_lvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssolbrusage).	
        end.
 	  if xxcstall_hist.xxcstall_scurisssobdnusage <> 0 then do:
         find first dpt_mstr where dpt_mstr.dpt_domain = global_domain no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsexp_acct,
			             input dpt_mstr.dpt_bvar_acc,
						 input "DEF",
						 input "DEF",
						 input "DEF",						 
						 input "DEF",
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssobdnusage).	
        end.		
 	  if xxcstall_hist.xxcstall_scurisssobdnrate <> 0 then do:
     assign
			codevaluein = "transition-in-burden".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsexp_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssobdnrate).	
        end.
	  if xxcstall_hist.xxcstall_scurisssolbrrate <> 0 then do:
       assign
			codevaluein = "transition-in-labor".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsbdn_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssolbrrate).	
        end.	
	  if xxcstall_hist.xxcstall_scurisssoraw <> 0 then do:
       assign
			codevaluein = "transition-in-raw".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssoraw).	
        end.
	  if xxcstall_hist.xxcstall_scurisssosf_mtl <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fslbr_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssosf_mtl).	
        end.
	  if xxcstall_hist.xxcstall_scurisssosf_lbr <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsbdn_acct, 
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssosf_lbr).	
        end.
	  if xxcstall_hist.xxcstall_scurisssosf_bdn <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsexp_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssosf_bdn).	
        end.
	  if xxcstall_hist.xxcstall_scurisssosf_ovh <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_fsexd_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssosf_ovh).	
        end.
	  if xxcstall_hist.xxcstall_scurisssosf_sub <> 0 then do:
       assign
			codevaluein = "transition-in-sfg".
			find b_codemstr where b_codemstr.code_domain  = global_domain
			                 and  b_codemstr.code_fldname = "xxcstallocation"
			                 and  b_codemstr.code_value   = codevaluein
							 no-lock no-error.

            run CreateJE(input pl_mstr.pl_rmar_acct,
			             input b_codemstr.code_cmmt,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssosf_sub).	
        end.
	  if xxcstall_hist.xxcstall_scurisssoothers <> 0 then do:
            run CreateJE(input pl_mstr.pl_fsexd_acct,
			             input pl_mstr.pl_ovh_acct,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_sub,
						 input pl_mstr.pl_inv_cc,						 
						 input pl_mstr.pl_inv_cc,
						 input pt_mstr.pt_part_type,						 
						 input pt_mstr.pt_part_type,
						 input pt_mstr.pt_group,						 
						 input pt_mstr.pt_group,  
						 input jedesc,
						 input xxcstall_hist.xxcstall_scurisssoothers).	
        end.



	  
  end. /** for each xxcstall_hist **/	 
	 
  
	 
	

   end. /* if available xxcstctrl_ctrl record */
    {us/mf/mfselprt.i "printer" 132}	
	
	for each tt_xxcstalljehist.
	
	export tt_xxcstalljehist.
	
	end.

	{us/mf/mfrtrail.i}
end.

Procedure CreateJE.
 define input PARAMETER  dracc   as character.
 define input parameter  cracc   as character.
 define input parameter  drsub   as character.
 define input parameter  crsub   as character.
 define input parameter  drcc    as character.
 define input parameter  crcc    as character.
 define input parameter  drsaf1  as character.
 define input parameter  crsaf1  as character.
 define input parameter  drsaf2  as character.
 define input parameter  crsaf2  as character.
 define input parameter  desc1    as character.
 define input parameter  amount    as decimal. 

			find tt_xxcstalljehist where tt_xxcstalljehist.xxcstallje_domain  = global_domain
			                         and tt_xxcstalljehist.xxcstallje_entity  = entity
									 and tt_xxcstalljehist.xxcstallje_site    = site
									 and tt_xxcstalljehist.xxcstallje_year    = li_year
									 and tt_xxcstalljehist.xxcstallje_period  = li_period
									 and tt_xxcstalljehist.xxcstallje_dr_acct = dracc
									 and tt_xxcstalljehist.xxcstallje_cr_acct = cracc
									 and tt_xxcstalljehist.xxcstallje_dr_cc   = drcc
									 and tt_xxcstalljehist.xxcstallje_cr_cc   = crcc
									 and tt_xxcstalljehist.xxcstallje_dr_sub  = drsub
									 and tt_xxcstalljehist.xxcstallje_cr_sub  = crsub
									 and tt_xxcstalljehist.xxcstallje_dr_saf1 = drsaf1
									 and tt_xxcstalljehist.xxcstallje_cr_saf1 = crsaf1
									 and tt_xxcstalljehist.xxcstallje_dr_saf2 = drsaf2
									 and tt_xxcstalljehist.xxcstallje_cr_saf2 = crsaf2							 
									 no-error.
			if not available tt_xxcstalljehist then do:
			create tt_xxcstalljehist.
            assign
              tt_xxcstalljehist.xxcstallje_domain  = global_domain
              tt_xxcstalljehist.xxcstallje_entity  = entity
              tt_xxcstalljehist.xxcstallje_site    = site
              tt_xxcstalljehist.xxcstallje_year    = li_year
              tt_xxcstalljehist.xxcstallje_period  = li_period
              tt_xxcstalljehist.xxcstallje_dr_acct = dracc
              tt_xxcstalljehist.xxcstallje_cr_acct = cracc
              tt_xxcstalljehist.xxcstallje_dr_cc   = drcc
              tt_xxcstalljehist.xxcstallje_cr_cc   = crcc
              tt_xxcstalljehist.xxcstallje_dr_sub  = drsub
              tt_xxcstalljehist.xxcstallje_cr_sub  = crsub
              tt_xxcstalljehist.xxcstallje_dr_saf1 = drsaf1
              tt_xxcstalljehist.xxcstallje_cr_saf1 = crsaf1
              tt_xxcstalljehist.xxcstallje_dr_saf2 = drsaf2
              tt_xxcstalljehist.xxcstallje_cr_saf2 = crsaf2			  
              tt_xxcstalljehist.xxcstallje_desc    = desc1	  
              tt_xxcstalljehist.xxcstallje_date    = today
			  tt_xxcstalljehist.xxcstallje_time    = time
			  tt_xxcstalljehist.xxcstallje_userid  = global_userid
			  .
			  end.
			  assign
			  tt_xxcstalljehist.xxcstallje_dr_amt  = tt_xxcstalljehist.xxcstallje_dr_amt + amount
              tt_xxcstalljehist.xxcstallje_cr_amt  = tt_xxcstalljehist.xxcstallje_cr_amt + amount.
 
 
END.